//简单工厂模式
#include<iostream>
#include<string>
#include<memory>
using namespace std;

class Fruit
{
public:
    Fruit(){}
    virtual void show()=0;
};
class Apple:public Fruit
{
public:
    Apple(){}
    void show() override
    {
        cout<<"这是一个苹果"<<endl;
    }
};
class Banana:public Fruit
{
public:
    Banana(){}
    void show() override
    {
        cout<<"这是一个香蕉"<<endl;
    }
};

class Factor
{
public:
    static shared_ptr<Fruit> create(const string& name)
    {
        if(name=="苹果"){
            return make_shared<Apple>();
        }
        else if(name=="香蕉"){
            return make_shared<Banana>();
        }
    }
};
int main()
{
    shared_ptr<Fruit> sp=Factor::create("苹果");
    sp->show();
    sp=Factor::create("香蕉");
    sp->show();
    return 0;
}